package com.ecube.maintenance.biz.apis.impl;

import com.ecube.maintenance.biz.apis.ISellerAction;
import com.ecube.maintenance.biz.commons.Constants;
import com.ecube.maintenance.biz.commons.ICCallBack;
import com.ecube.maintenance.biz.commons.ITestDataProvider;
import com.ecube.maintenance.biz.commons.VolleySingleton;
import com.ecube.maintenance.pojos.AddressInfo;
import com.ecube.maintenance.pojos.BaseInfo;
import com.ecube.maintenance.pojos.SellerInfo;
import com.ecube.maintenance.pojos.SellerListInfo;
import com.ecube.maintenance.utils.BaseParameters;
import com.google.gson.reflect.TypeToken;

/**
 * Created by Trible Chen on 2014/9/7.
 */
public class SellerAction {

    public static ProxySeller proxySeller = new ProxySeller();

//    获取服务商列表
    public static void fetchSellerList(String sid,AddressInfo addressInfo,int skip,
                                       String searchDate,String carFactory,
                                       String keyword,String sortBy,
                                       ICCallBack<SellerListInfo> callBack){
        if ( addressInfo == null ){
            throw new IllegalArgumentException("addressInfo can't be null");
        }
        double lon = addressInfo.getLon();
        double lat = addressInfo.getLat();
        String cityName = addressInfo.getAddress();
        int count = Constants.COUNT;
        proxySeller.fetchSellerList(sid, lon, lat, cityName, skip, count, searchDate, carFactory, keyword, sortBy, callBack);
    }

//    获取服务商详情
    public static void fetchSellerDetail(String sid, String spID, String date, ICCallBack<SellerInfo> callBack){
        proxySeller.fetchSellerDetail(sid,spID,date,callBack);
    }
//    收藏或者取消收藏
    public static void collectSeller(String sid, String spID, int collectType, ICCallBack callBack){
        proxySeller.collectSeller(sid,spID,collectType,callBack);
    }
//    求工位
    public static  void claimProduct(String sid, String spID, AddressInfo addressInfo, ICCallBack callBack){
        if (addressInfo == null ){
            throw new IllegalArgumentException("addressInfo can't be null");
        }
        double lon = addressInfo.getLon();
        double lat = addressInfo.getLat();
        proxySeller.claimProduct(sid,spID,lon,lat,callBack);
    }






    private static  class ProxySeller implements ISellerAction{
        BaseParameters getParameter(){
            return null;
        }
        @Override
        public void fetchSellerList(String sid, double lon, double lat, String cityName,
                                    int skip, int count, String searchDate,
                                    String carFactory, String keyword, String sortBy,
                                    ICCallBack<SellerListInfo> callBack) {
            BaseParameters parameters = new BaseParameters();
            parameters.add("action","app_GetSPList");
            parameters.add("sid",sid);
            parameters.add("lon",lon+"");
            parameters.add("lat",lat+"");
            parameters.add("cityName",cityName);
            parameters.add("cursor",skip+"");
            parameters.add("count",count+"");
            parameters.add("searchDate",searchDate);
            parameters.add("carFactory",carFactory);
            parameters.add("keyword",keyword);
            parameters.add("sortBy",sortBy);
            ITestDataProvider provider = null ;
            if (Constants.LOCAL_TEST_DATA){
                provider = new ITestDataProvider() {
                    @Override
                    public String getTestData() {
                        return "{\n" +
                                "\"errorCode\": 10000,\n" +
                                "\"errorMsg\": \"\",\n" +
                                "\"returnData\":{\n" +
                                "\"count\": 5,\n" +
                                "\"cursor\": 10,\n" +
                                "\"spList\":[\n" +
                                "{\n" +
                                "\"spID\": \"服务商 ID\",\n" +
                                "\"spName\": \"服务商名称\",\n" +
                                "\"carBrand\": \"服务商品牌\",\n" +
                                "\"spLogo\": \"http://t10.baidu.com/it/u=60485490,1419274085&fm=56\",\n" +
                                "\"distance\": 1000,\n" +
                                "\"origPrice\": 1000,\n" +
                                "\"discountPrice\": 500,\n" +
                                "\"isClaim\": true,\n" +
                                "\"lon\": 106.1,\n" +
                                "\"lat\": 43.1\n" +
                                "},\n" +
                                "{\n" +
                                "\"spID\": \"服务商 ID\",\n" +
                                "\"spName\": \"服务商名称\",\n" +
                                "\"carBrand\": \"服务商品牌\",\n" +
                                "\"spLogo\": \"http://t10.baidu.com/it/u=60485490,1419274085&fm=56\",\n" +
                                "\"distance\": 1000,\n" +
                                "\"origPrice\": 1000,\n" +
                                "\"discountPrice\": 500,\n" +
                                "\"isClaim\": true,\n" +
                                "\"lon\": 106.1,\n" +
                                "\"lat\": 43.1\n" +
                                "}\n" +
                                "]\n" +
                                "}\n" +
                                "}";
                    }
                };
            }
            TypeToken<BaseInfo<SellerListInfo>> typeToken = new TypeToken<BaseInfo<SellerListInfo>>(){};
            VolleySingleton.getInstance().addToRequestQueue(parameters,callBack,typeToken.getType(),provider);

        }

        @Override
        public void fetchSellerDetail(String sid, String spID, String date, ICCallBack<SellerInfo> callBack) {
            BaseParameters parameters = new BaseParameters();
            parameters.add("action","app_GetSPDetail");
            parameters.add("sid",sid);
            parameters.add("spID",spID);
            parameters.add("date",date);
            ITestDataProvider provider = null ;
            if (Constants.LOCAL_TEST_DATA){
                provider = new ITestDataProvider() {
                    @Override
                    public String getTestData() {
                        return "{\n" +
                                "\"errorCode\": 10000,\n" +
                                "\"errorMsg\": \"\",\n" +
                                "\"returnData\": {\n" +
                                "\"spID\": \"服务商 ID\",\n" +
                                "\"spName\": \"服务商名称\",\n" +
                                "\"carBrand\": \"服务商品牌，xx4S 店\",\n" +
                                "\"dailyLimit\": 5,\n" +
                                "\"leftLimit\":3,\n" +
                                "\"address\": \"服务商地址\",\n" +
                                "\"lon\": \"经度\",\n" +
                                "\"lat\": \"纬度\",\n" +
                                "\"serviceTel\": \"服务电话\",\n" +
                                "\"rescueTel\": \"救援电话\",\n" +
                                "\"images\": [\n" +
                                "\"图片地址 1\",\n" +
                                "\"图片地址 2\",\n" +
                                "\"图片地址 n\"\n" +
                                "],\n" +
                                "\"brandLogo\": \"品牌 Logo\",\n" +
                                "\"isCollect\": \"是否被该客户收藏\",\n" +
                                "\"comment\": {\n" +
                                "\"commentCount\": 2,\n" +
                                "\"score\": 3\n" +
                                "},\n" +
                                "\"productList\": [{\n" +
                                "\"productID\": \"产品 ID\",\n" +
                                "\"productName\": \"产品名称\", \n" +
                                "\"productImg\": \"产品图片 url\",\n" +
                                "\"serviceStartTime\" : \"产品开始时间\",\n" +
                                "\"serviceEndTime\" : \"产品截止时间\",\n" +
                                "\"origPrice\": \"原价\",\n" +
                                "\"discountPrice\": \"特价\",\n" +
                                "\"serviceItems\": [\n" +
                                "\"项目 1\",\n" +
                                "\"项目 2\",\n" +
                                "\"项目 n\"\n" +
                                "]\n" +
                                "},\n" +
                                "{\n" +
                                "\"productID\": \"产品 ID\",\n" +
                                "\"productName\": \"产品名称\",\n" +
                                "\"productImg\": \"产品图片 url\",\n" +
                                "\"serviceStartTime\" : \"产品开始时间\",\n" +
                                "\"serviceEndTime\" : \"产品截止时间\",\n" +
                                "\"origPrice\": \"原价\",\n" +
                                "\"discountPrice\": \"特价\",\n" +
                                "\"serviceItems\": [\n" +
                                "\"项目 1\",\n" +
                                "\"项目 2\",\n" +
                                "\"项目 n\"\n" +
                                "]\n" +
                                "}\n" +
                                "]\n" +
                                "}\n" +
                                "}";
                    }
                };
            }
            TypeToken<BaseInfo<SellerInfo>> typeToken = new TypeToken<BaseInfo<SellerInfo>>(){};
            VolleySingleton.getInstance().addToRequestQueue(
                    parameters,callBack,typeToken.getType(),provider);

        }

        @Override
        public void collectSeller(String sid, String spID, int collectType, ICCallBack callBack) {
            BaseParameters parameters = new BaseParameters();
            parameters.add("action","app_AddCollect");
            parameters.add("sid",sid);
            parameters.add("spID",spID);
            parameters.add("collectType",collectType+"");
            ITestDataProvider provider = null ;
            if (Constants.LOCAL_TEST_DATA){
                provider = new ITestDataProvider() {
                    @Override
                    public String getTestData() {
                        return "{\n" +
                                "\"errorCode\":10000,\n" +
                                "\"errorMsg\": \"\"\n" +
                                "}";
                    }
                };
            }
            VolleySingleton.getInstance().addToRequestQueue(
                    parameters,callBack,BaseInfo.class,provider);
        }

        @Override
        public void claimProduct(String sid, String spID, double lon, double lat, ICCallBack callBack) {
            BaseParameters parameters = new BaseParameters();
            parameters.add("action","app_AddClaimProduct");
            parameters.add("sid",sid);
            parameters.add("spID",spID);
            parameters.add("lon",lon+"");
            parameters.add("lat",lat+"");
            ITestDataProvider provider = null ;
            if (Constants.LOCAL_TEST_DATA){
                provider = new ITestDataProvider() {
                    @Override
                    public String getTestData() {
                        return "{\n" +
                                "\"errorCode\": 10000,\n" +
                                "\"errorMsg\": \"\"\n" +
                                "}";
                    }
                };
            }
            VolleySingleton.getInstance().addToRequestQueue(
                    parameters,callBack,BaseInfo.class,provider);
        }
    }
}
